package main

import "fmt"

func main() {

	m := map[string]string{
		"name":    "thank",
		"country": "china",
		"sex":     "man",
	}

	fmt.Println(m)

	m2 := make(map[string]int) // 通过make内建函数来定义
	fmt.Println(m2 == nil)     // false: m2 is empty map
	fmt.Println(m2)            // map[]

	var m3 map[string]string
	fmt.Println(m3 == nil) // true: m3 is nil
	fmt.Println(m3)        // map[]

	fmt.Println("--- Traversing map m ---")
	for i, v := range m {
		fmt.Println(i, v)
	}

	fmt.Println("--- Getting map values ---")
	fmt.Println("m[\"name\"]: ", m["name"])

	if country, ok := m["country"]; ok {
		fmt.Println("m[country]:", country)
	} else {
		fmt.Println("key: m[country] not exists")
	}

	fmt.Println("--- Deleting map values ---")
	sex, ok := m["sex"]
	fmt.Printf("m[%q] before delete is: %v\n", sex, ok)
	delete(m, "sex")

	sex, ok = m["sex"]
	fmt.Printf("m[%q] after delete is: %v\n", sex, ok)
}
